//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) {
        //1.BM19寻找峰值(找上坡,双指针)
        public int findPeakElement (int[] nums) {
            int len = nums.length;
            int left = 0;
            int right = len - 1;
            int mid = 0;
            while(left < right) {
                mid = (left + right) / 2;
                if(nums[mid] > nums[mid+1]) {
                    right = mid;
                } else {
                    left = mid + 1;
                }
            }
            return right;
        }
        //2.BM22比较版本号
        //version1.charAt(i) - '0'消除字符串中的0并且可以将字符串转化为数字
        public int compare (String version1, String version2) {
            int n1 = version1.length();
            int n2 = version2.length();
            int i = 0, j = 0;
            //直到某个字符串结束
            while (i < n1 || j < n2) {
                int num1 = 0;
                //从下一个点前截取数字
                while (i < n1 && version1.charAt(i) != '.') {
                    num1 = num1 * 10 + (version1.charAt(i) - '0');
                    i++;
                }
                //跳过点
                i++;
                int num2 = 0;
                //从下一个点前截取数字
                while (j < n2 && version2.charAt(j) != '.') {
                    num2 = num2 * 10 + (version2.charAt(j) - '0');
                    j++;
                }
                //跳过点
                j++;
                //比较数字大小
                if (num1 > num2)
                    return 1;
                if (num1 < num2)
                    return -1;
            }
            //版本号相同
            return 0;
        }
    }
}